package com.lgk.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lgk.domain.User;
import com.lgk.mapper.UserMapper;
import com.lgk.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    //分页查询
    @Override
    public PageInfo<User> getPageUser(Integer pageNum) {
        PageHelper.startPage(pageNum, 6);
        List<User> allUser = userMapper.getAllUser();
        return new PageInfo<>(allUser, 5);
    }

    //添加用户
    @Override
    public void addUser(User user) {
        userMapper.addUser(user);
    }

    //id的获取
    @Override
    public User getById(Integer id) {
        return userMapper.getById(id);
    }

    //修改用户
    @Override
    public void updateUser(User user) {
        userMapper.updateUser(user);
    }

    //删除用户
    @Override
    public void deleteUser(Integer id) {
        userMapper.deleteUser(id);
    }

    //登录
    @Override
    public boolean getByUserNameAndPassword(User user) {
        return (userMapper.getByUserNameAndPassword(user) != null);
    }

    //名字模糊查询
    @Override
    public PageInfo<User> getPageByName(String name, Integer pageNum) {
        PageHelper.startPage(pageNum, 6);
        List<User> allNameUser = userMapper.getByNameAllUser(name);
        return new PageInfo<>(allNameUser, 5);
    }
}
